<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.org/schema/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:tr="http://myfaces.apache.org/trinidad"
                template="layout/template.xhtml">

<ui:define name="body">

   <tr:panelBox text="Artist" background="medium">
	  	<h:form id="artist">
	  		<s:validateAll>
	    	<tr:panelFormLayout>
	    		<tr:inputText label="Artist" id="name" value="#{artist.name}" readOnly="#{not identity.loggedIn}" required="true"/>
	    		<tr:panelLabelAndMessage label="Band Members" rendered="#{artist.class.simpleName eq 'Band'}">
					<ul>
			    		<tr:iterator value="#{artist.bandMembers}" var="bandMember">
			    			<li>
			    				<tr:inputText simple="true" value="#{bandMember.name}" readOnly="#{not identity.loggedIn}" id="bandMember"/>
			    			</li>
			    		</tr:iterator>
					</ul>
		    		<f:facet name="end">
		    			<h:commandButton id="addBandMember" action="#{artistHome.addBandMember}" value="Add Band Member" rendered="#{identity.loggedIn}"/>
		    		</f:facet>
		    	</tr:panelLabelAndMessage>
		    	<tr:panelLabelAndMessage label="Details">
		    		<tr:inputText simple="true" value="#{artist.description}" rendered="#{identity.loggedIn}" rows="4" columns="60" id="description">
		    			 <f:ajax event="keyup" render="description_preview" requestDelay="3000" ignoreDupResponces="true" eventsQueue="previewQueue" />
		    		</tr:inputText>
		    		<s:div style="width: 300px" id="description_preview">

					   	<s:formattedText value="#{artist.description}" rendered="#{not empty artist.description}" />
			    		<tr:outputText value="None known" rendered="#{empty artist.description}" />
					</s:div>
				</tr:panelLabelAndMessage>
		    	<tr:panelLabelAndMessage label="Discs">
		    		<tr:table value="#{artist.discs}" var="disc" rows="5" emptyText="None Known" id="discs">
			    		<tr:column>
			    			<f:facet name="header">
			    				Disc
			    			</f:facet>
			    			<tr:inputText value="#{disc.name}" readOnly="#{not identity.loggedIn}"/>
			    		</tr:column>
			    		<tr:column>
			    			<f:facet name="header">
			    				Released
			    			</f:facet>
			    			<tr:inputNumberSpinbox label="Release Date" value="#{disc.release}" minimum="1900" maximum="2100" stepSize="1" readOnly="#{not identity.loggedIn}" columns="4" />
			    		</tr:column>
			    		<f:facet name="detailStamp">
					    	<s:div style="width: 300px;">
							   	<s:formattedText value="#{disc.description}" rendered="#{not empty disc.description}"  />
					    		<tr:outputText value="None known" rendered="#{empty disc.description}" />
							</s:div>
				 		</f:facet>
			    	</tr:table>
			    	<f:facet name="end">
		    			<h:commandButton id="addDisc" action="#{artistHome.addDisc}" value="Add Disc" rendered="#{identity.loggedIn}"/>
		    		</f:facet>
		    	</tr:panelLabelAndMessage>
	    	</tr:panelFormLayout>
	   	</s:validateAll>

	   	<tr:panelButtonBar rendered="#{identity.loggedIn}">
	   		<h:commandButton action="#{artistHome.update}" value="Save" rendered="#{artistHome.managed}" id="update"/>
	   		<h:commandButton action="#{artistHome.persist}" value="Save" rendered="#{not artistHome.managed}" id="persist"/>
	   		<s:button action="cancel" value="Cancel" id="cancel"/>
	   	</tr:panelButtonBar>
	  	</h:form>
    </tr:panelBox>

</ui:define>
</ui:composition>
